using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ClassLetras;  

namespace FormulaCSharp
{
    public partial class TestForm : Form
    {
        NumberToLetters numberToLetters = new NumberToLetters(); 

        public TestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (double.Parse(txtNumber.Text) != 0)
            {
                numberToLetters.ShowDecimals = chkShowDecimal.Checked;
                numberToLetters.Number = double.Parse(txtNumber.Text);

                txtLetters.Text = numberToLetters.GetNumberToLetters();

                dgView.DataSource = numberToLetters.GetList();          
                dgView.Refresh();
            }
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (!((double)udNumber.Value <= 0))
            {
                numberToLetters.ShowDecimals = chkShowDecimal.Checked;
                numberToLetters.Number = Convert.ToDouble(udNumber.Value);

                txtLetters.Text = numberToLetters.GetNumberToLetters();

                dgView.DataSource = numberToLetters.GetList();
                dgView.Refresh();
            }
        }

        private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) ||
                Convert.ToInt32(e.KeyChar) == 8 ||
                Convert.ToInt32(e.KeyChar) == 13 || (Convert.ToInt32(e.KeyChar) == 46 && this.chkShowDecimal.Checked)  )
                e.Handled = false;
            else
                e.Handled = true; 
        }

        private void chkShowDecimal_CheckedChanged(object sender, EventArgs e)
        {
            txtNumber.Clear();  
        }

        private void rbSpanish_CheckedChanged(object sender, EventArgs e)
        {
            if (rbSpanish.Checked)
            {
                chkShowDecimal.Enabled = true;
                numberToLetters.Language = new SpanishLanguage();
            }
        }

        private void rbEnglish_CheckedChanged(object sender, EventArgs e)
        {
            if (rbEnglish.Checked)
            {
                chkShowDecimal.Enabled = true;
                numberToLetters.Language = new EnglishLanguage();
            }
        }

        private void rbRoman_CheckedChanged(object sender, EventArgs e)
        {
            if (rbRoman.Checked)
            {
                chkShowDecimal.Checked = false;
                chkShowDecimal.Enabled = false; 
                numberToLetters.Language = new RomanLanguage();
            }
        }

        
    }
}